package com.tian.netty.message.req;

import com.tian.netty.test.charging.ChargingDataDto;
import com.tian.util.BCDUtil;
import com.tian.util.DateUtils;

import java.math.BigDecimal;
import java.util.Arrays;

/**
 * {@code @description:} 实时充电数据上报
 *  msgObject: [104, 64, 0, 0, 0, 0, 1, 0, 0, 2, 0, 32, 36, 8, 37, 9, 71, 52, 0, 32, 36, 8, 37, 9, 71, 52, 0, 16, 0, 80, 16, 0, 0, 1, 0, 0]
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-05-14 20:50
 * {@code @version:} 1.0
 */
public class ChargingDataReq extends RequestMsgBase<ChargingDataDto> {
    public ChargingDataReq(short msgType, byte[] msgObject) {
        super(msgType, msgObject);
    }

    @Override
    public ChargingDataDto parse() {
        ChargingDataDto chargingDataDto = new ChargingDataDto();
        chargingDataDto.setGunNo(BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 2, 10)));
        chargingDataDto.setChargingStartTime(DateUtils.parse(BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 10, 18)),DateUtils.FORMAT_NO_SECOND));
        chargingDataDto.setChargingEndTime(DateUtils.parse(BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 18, 26)),DateUtils.FORMAT_NO_SECOND));
        BigDecimal chargeNum=new BigDecimal(BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 26, 30)));
        chargingDataDto.setChargingCount(chargeNum.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP));
        String userId=BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 30, 34));
        chargingDataDto.setUserId(Long.parseLong(userId));
        String remainedChargingTime=BCDUtil.bcd2Str(Arrays.copyOfRange(msgObject, 34, 38));
        chargingDataDto.setRemainedChargingTime(Integer.parseInt(remainedChargingTime));
        return chargingDataDto;
    }
}
